/**
 * @ClassName TestRecursion
 * @Author 小坏 阶乘
 * @Date 2022/1/12、10:58
 * @Version 1.0
 */
public class TestRecursion {
    public static void main(String[] args) {
        System.out.println(4*3*2*1);
        int factorial = factorial(5);

        System.out.println(factorial);
        System.out.println("#######################");

        int fact = fact(5);
//        System.out.println(fact);
    }


    //1、循环
    public static int factorial(int n) {
        int result = 1;
        for (int i = 1; i <= n; i++) {
            result *= i;
        }
        return result;
    }

    //2、递归

    public static int fact(int n) {
        if (n == 0) return 1;
        int i = fact(n - 1) * n;
        System.out.println(i);
        return i;
    }


}



//5-1 = 4 *5 =20
//4-1= 3*20 =60
//3-1 =2 * 60 = 120
//2-1 =1 * 120 =120

